package com.qiang.manager.service;

import com.qiang.manager.dao.IteacherDao;
import com.qiang.manager.domain.Teacher;
import com.qiang.manager.factory.Factory;

import java.util.ArrayList;

public class TeacherServiceImp implements IteacherService {

    IteacherDao dao = Factory.getTeacherDao();

    @Override
    public void addTeacher(Teacher teacher) {
        dao.addTeacher(teacher);
    }

    @Override
    public void deleteTeacher(String id) {
        dao.deleteTeacher(id);

    }

    @Override
    public void updateTeacher(String id, Teacher newtea) {

        dao.updateTeacher(id, newtea);

    }

    @Override
    public ArrayList<Teacher> findTeacher() {
        ArrayList<Teacher> teacher = dao.findTeacher();
        return teacher;
    }

    @Override
    //判断id是否存在的方法
    public boolean Exit(String id) {
        ArrayList<Teacher> student = dao.findTeacher();
        //遍历集合
        for (int i = 0; i < student.size(); i++) {
            if (student.get(i) != null && student.get(i).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }
}
